package com.nobug.controller.brand;

import com.nobug.bean.BaseRespVo;
import com.nobug.bean.brand.BO.BrandCreateBO;
import com.nobug.bean.brand.Brand;
import com.nobug.bean.brand.VO.BrandCreateVO;
import com.nobug.bean.brand.VO.BrandListVO;
import com.nobug.service.brand.BrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("admin/brand/")
public class BrandController {

    @Autowired
    BrandService service;


    @RequestMapping("list")
    public BaseRespVo<BrandListVO> brandList(Integer page, Integer limit, String sort, String order, Integer id, String name) {
        if(null == id && null == name) {
            BaseRespVo<BrandListVO> respVo = service.queryBrands(page, limit, sort, order);
            return respVo;
        }
        else{
            BaseRespVo<BrandListVO> respVo = service.queryBrands(page, limit, sort, order, id, name);
            return respVo;
        }

    }

    @RequestMapping("create")
    public BaseRespVo<BrandCreateVO> brandCreate(@RequestBody Brand brand) {
        BaseRespVo<BrandCreateVO> brandCreateVOBaseRespVo = service.brandInsert(brand);
        return brandCreateVOBaseRespVo;
    }

    @RequestMapping("delete")
    public BaseRespVo brandDelete(@RequestBody Brand brand){
        service.deleteBrand(brand);
        return BaseRespVo.ok();
    }
}
